<?php

/*
 * Redirecting requests to 'index.php/some/url'
 * This is getting wrong MPS parameters because for MPS '/index.php/some/url' is different than '/some/url'
 * and the dart tags set for '/some/url' page are missing in the resond.   
 */
$subject  = $_SERVER['REQUEST_URI'];
$patern = '/index.php\/(.*)/';
$res = preg_match($patern, $subject, $matches);
if($res>0)
{
    header("location:/".$matches[1]);
    exit;
}

/*
 * The above condition assures that any request to 'index.php/some/url' will get redirected to '/some/url'
 * But what about request to 'index.php'? Below code will redirect '/index.php' to '/'
 */
if($subject === '/index.php'){
  header("location:/");
  exit;
}

// To STOP direct access
define('VIA_INDEX', TRUE);

$app_pathinfo = pathinfo(__FILE__);
define('DOCROOT', $app_pathinfo['dirname'].DIRECTORY_SEPARATOR);
define('HELPERS', DOCROOT.'helpers'.DIRECTORY_SEPARATOR);
define('CONTROLLERS', DOCROOT.'controllers'.DIRECTORY_SEPARATOR);

$controller_name = ($subject === '/') ? CONTROLLERS.'home.php' : CONTROLLERS.trim($subject,'/').'.php';
if(file_exists($controller_name)){
    include $controller_name;
}else{
    header("HTTP/1.0 404 Not Found");
}

?>